package Stack;

/**
 * @author yyq
 * @create 2021-10-08 17:18
 */
public class Stack<T> {
    private LinkNode<T> header;

    public Stack() {
        header=new LinkNode<T>(null,null);
    }

    public Boolean isEmpty(){
        if(header.nextNode==null)
            return true;
        else return false;
    }

    public void push(T data){
        if(isEmpty()){
            header.nextNode=new LinkNode<T>(data,null);
        }
        else {
            LinkNode<T> temp=header.nextNode;
            header.nextNode=new LinkNode<T>(data,temp);
        }
    }

    public T pop(){
        if(isEmpty()) return null;
        if(!isEmpty()){
            LinkNode<T> result=header.nextNode;
            header.nextNode=header.nextNode.nextNode;
            return result.data;
         }
        return null;
    }


}

class LinkNode<T>{
    public T data;
    public LinkNode<T> nextNode;

    public LinkNode() {
    }

    public LinkNode(T data) {
        this.data = data;
    }

    public LinkNode(T data, LinkNode<T> nextNode) {
        this.data = data;
        this.nextNode = nextNode;
    }
}
